package com.lovo.controller;

import com.lovo.dto.UserDTO;
import com.lovo.model.UserDO;
import com.lovo.result.GlobalHandleException;
import com.lovo.result.ResponseResult;
import com.lovo.service.UserService;
import com.lovo.utils.ResultFactory;
import com.lovo.vo.ResultVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @title
 * @author: luo
 * @date: 2020/11/17 16:55
 */
@RestController
@RequestMapping("/api/users")
@ResponseResult
public class UserController {
    @Resource
    private UserService userService;

    @PostMapping("/login")
    public Object login(@RequestBody UserDTO userDTO, HttpServletRequest request) throws GlobalHandleException {
        UserDO login = userService.login(userDTO);
        request.getSession().setAttribute("user",login);
        return login;
    }

    @PostMapping("")
    public void register(@RequestBody UserDTO userDTO) throws GlobalHandleException {
        userService.register(userDTO);
    }





}
